/*
 * IIC.h
 *
 *  Created on: Jul 11, 2021
 *      Author: 本地账户
 */

#ifndef INC_IIC_H_
#define INC_IIC_H_


#include "sys.h"


#define SDA1_IN()  {GPIOB->MODER&=~(3<<(9*2));GPIOB->MODER|=0<<9*2;}	//PB9输入模式
#define SDA1_OUT() {GPIOB->MODER&=~(3<<(9*2));GPIOB->MODER|=1<<9*2;} //PB9输出模式

#define SDA2_IN()  {GPIOB->MODER&=~(3<<(6*2));GPIOB->MODER|=0<<6*2;}	//PB6输入模式
#define SDA2_OUT() {GPIOB->MODER&=~(3<<(6*2));GPIOB->MODER|=1<<6*2;} //PB6输出模式

#define SDA3_IN()  {GPIOD->MODER&=~(3<<(6*2));GPIOD->MODER|=0<<6*2;}	//PD6输入模式
#define SDA3_OUT() {GPIOD->MODER&=~(3<<(6*2));GPIOD->MODER|=1<<6*2;} //PD6输出模式

#define IIC1_SCL   PBout(8) //SCL
#define IIC1_SDA   PBout(9) //SDA
#define READ1_SDA  PBin(9)  //输入SDA

#define IIC2_SCL   PBout(5) //SCL
#define IIC2_SDA   PBout(6) //SDA
#define READ2_SDA  PBin(6)  //输入SDA

#define IIC3_SCL   PDout(5) //SCL
#define IIC3_SDA   PDout(6) //SDA
#define READ3_SDA  PDin(6)  //输入SDA

void IIC1_Init(void);
void IIC2_Init(void);
void IIC3_Init(void);

void IIC1_Start(void);
void IIC2_Start(void);
void IIC3_Start(void);

void IIC1_Stop(void);
void IIC2_Stop(void);
void IIC3_Stop(void);

void IIC1_Send_Byte(u8 txd);
void IIC2_Send_Byte(u8 txd);
void IIC3_Send_Byte(u8 txd);

u8 IIC1_Read_Byte(unsigned char ack);
u8 IIC2_Read_Byte(void);
u8 IIC3_Read_Byte(unsigned char ack);

u8 IIC1_Wait_Ack(void);
u8 IIC2_Wait_Ack(void);
u8 IIC3_Wait_Ack(void);

void IIC1_Ack(void);
void IIC2_Ack(void);
void IIC3_Ack(void);

void IIC1_NAck(void);
void IIC2_NAck(void);
void IIC3_NAck(void);


void IIC1_Write_One_Byte(u8 daddr,u8 addr,u8 data);
void IIC2_Write_One_Byte(u8 daddr,u8 addr,u8 data);
void IIC3_Write_One_Byte(u8 daddr,u8 addr,u8 data);

u8 IIC1_Read_One_Byte(u8 daddr,u8 addr);
u8 IIC2_Read_One_Byte(u8 daddr,u8 addr);
u8 IIC3_Read_One_Byte(u8 daddr,u8 addr);


#endif /* INC_IIC_H_ */
